package a66weding.com.jiehuntong.pager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import org.json.JSONException;

import java.util.HashMap;

import a66weding.com.jiehuntong.R;
import a66weding.com.jiehuntong.activity.Diy_HeadActivity;
import a66weding.com.jiehuntong.application.DataWareHourse;
import a66weding.com.jiehuntong.beans.ErrorBean;
import a66weding.com.jiehuntong.beans.GuestsseatBean;
import a66weding.com.jiehuntong.beans.HttpRequestBean;
import a66weding.com.jiehuntong.beans.SuccessBean;
import a66weding.com.jiehuntong.beans.User;
import a66weding.com.jiehuntong.common.utils.SharesUtils;
import a66weding.com.jiehuntong.http.HttpHandleUtil;
import a66weding.com.jiehuntong.http.OnNetResultListener;
import a66weding.com.jiehuntong.http.RequestCode;
import a66weding.com.jiehuntong.http.UrlDealUtil;
import a66weding.com.jiehuntong.pager.BasePager;

/**
 * Created by admin on 2016/6/14.
 */
public class Diy_YusuanPager extends BasePager implements View.OnClickListener, OnNetResultListener {

    private View mBodyView;
    private Button btn_finish;
    private String mobileNum;
    private EditText et_editmoney;
    //输入的金额;
    private String WeddingBudget = null;
    private LinearLayout Linear_back;
    public static String MARRY_BUDGET = "marry_budget";
    public Diy_YusuanPager(Activity activity) {
        super(activity);
    }

    @Override
    protected View getView() {
        mBodyView = View.inflate(mActivity, R.layout.activity_diy_yusuan, null);
        et_editmoney = (EditText) mBodyView.findViewById(R.id.yusuan_editmoney_et);
        Linear_back = (LinearLayout) mBodyView.findViewById(R.id.yusuan_L_back);
        initView();
        initData();
        return mBodyView;
    }

    private void initView() {
        btn_finish = (Button) mBodyView.findViewById(R.id.yusuan_finish_btn);
        btn_finish.setOnClickListener(this);
    }

    public void initData() {
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.yusuan_finish_btn:
                WeddingBudget = et_editmoney.getText().toString();
//                upDateBudget();
                //保存数据到xml中;
                saveshareXml(MARRY_BUDGET);
                break;
            //返回键
            case R.id.yusuan_L_back:

                break;
        }
    }

    /**
     * 提交结婚预算;
     */
    private void upDateBudget() {
        HashMap<String, String> mapData = new HashMap<String, String>();
        mapData.put("WeddingBudget", WeddingBudget);
        String userUrl = UrlDealUtil.getRealUrl(RequestCode.UPDATE_WEDDINGBUDGET);
        User user = DataWareHourse.getInstance().getmUser();
        mobileNum = user.getData().get(0).getNvc_MobilePhone();
        userUrl += mobileNum;
        HttpRequestBean requestBean = new HttpRequestBean(RequestCode.POSTEQUEST, userUrl, this, GuestsseatBean.class, RequestCode.UPDATE_WEDDINGBUDGET, mapData);
        HttpHandleUtil.executeCommonPost(mActivity, requestBean);
    }

    @Override
    public void onSucess(SuccessBean sucessbean)  {

    }

    @Override
    public void onError(ErrorBean errorBean) {

    }

    private void saveshareXml(String name){
        SharesUtils.getInstance(mActivity).writeXML( name,WeddingBudget);
        Toast.makeText(mActivity,"保存数据成功",Toast.LENGTH_SHORT).show();
    }
    private String getshareXml(String name){
        return  SharesUtils.getInstance(mActivity).readXML(name);
    }
}
